import moment from 'moment'
export default {
  // 身份证脱敏
  judgeCard(value) {
    if (!value) return ''
    let reg = /^(.{6}).*(.{4})$/
    return value.replace(reg, '$1*************$2')
  },
  distanceFormat(value) {
    if (!value) {
      return ''
    } else if (value > 1000) {
      return (value / 1000).toFixed(2) + '公里'
    } else {
      return value + '米'
    }
  },
  amountFormat(value, point=2){
    if (!value) {
      return '0'
    } else if (value > 10000) {
      return (value / 10000).toFixed(point) + '万'
    } else {
      return value + '元'
    }
  },
  dateFormat(date, str = 'YYYY-MM-DD') {
    if (!date) return ''
    else return moment(new Date(date)).format(str)
  },
  numFormat(num, fixed = 0) {
    // console.log(date)
    if (num === null || num === undefined) return ''
    return Number(num).toFixed(fixed).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
  }
}
